﻿using System;
using System.Collections.Generic;

namespace Triangle
{
    /// <summary>
    /// вектор
    /// </summary>
    class Vector
    {
        public int X { get; private set; }
        public int Y { get; private set; }
        public double Length { get; private set; }
        /// <summary>
        /// создание вектора
        /// </summary>
        /// <param name="one"></param>
        /// <param name="two"></param>
        public Vector(Node one, Node two)
        {
            X = one.I - two.I;
            Y = one.J - two.J;
            Length = Math.Sqrt(X * X + Y * Y);
        }
        /// <summary>
        /// косинус угла между векторами
        /// </summary>
        /// <param name="one"></param>
        /// <param name="two"></param>
        /// <returns></returns>
        public static double CosAngle(Vector one, Vector two)
        {
            return (one.X * two.X + one.Y * two.Y)/(one.Length*two.Length);
        }
        /// <summary>
        /// Берет 3 вектора и должен вернуть перпенидикулярные
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List<Vector> GetRectVectors(List<Vector> list)
        {
            // магия
            var minId1 = 0;
            var minId2 = 1;
            if (list[2].Length < list[0].Length)
            {
                minId1 = 2;
                if (list[0].Length < list[1].Length)
                    minId2 = 0;
            } else if (list[2].Length < list[1].Length)
                minId2 = 2;

            return CosAngle(list[minId1], list[minId2]) == 0 ? new List<Vector> { list[minId1], list[minId2] } : new List<Vector>();
        }
        /// <summary>
        /// точка от применения вектора к точке(значение функции)
        /// </summary>
        /// <param name="one"></param>
        /// <returns></returns>
        public Node GetNode(Node one)
        {
            return new Node(one.I + X, one.J + Y);
        }
    }
}
